package com.erp.order.dn.dao.hibernate;

import com.erp.common.inv.input.dao.model.InvInputHead;
import com.erp.order.dn.dao.DeliveryNoteLineDao;
import com.erp.order.dn.dao.model.DeliveryNoteHead;
import com.erp.order.dn.dao.model.DeliveryNoteLine;
import com.erp.order.dn.dao.model.DeliveryNoteLineCO;
import org.apache.commons.lang.StringUtils;
import org.redragon.framework.hibernate.DaoSupport;
import org.redragon.framework.hibernate.model.Pages;
import org.redragon.framework.util.DaoCRUDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhoupan
 * @date 2021/4/9 11:23
 * @info
 */
@Repository
public class DeliveryNoteLineDaoImpl implements DeliveryNoteLineDao {
    //注入DaoSupport工具类
    @Autowired
    private DaoSupport daoSupport;

    @Override
    public void insertDataObject(DeliveryNoteLine deliveryNoteLine) {
        daoSupport.insertDataTransaction(deliveryNoteLine);
    }

    @Override
    public void updateDataObject(DeliveryNoteLine deliveryNoteLine) {
        daoSupport.updateDataTransaction(deliveryNoteLine);
    }

    @Override
    public void insertOrUpdateDataObject(DeliveryNoteLine deliveryNoteLine) {
        this.daoSupport.insertOrUpdateDataTransaction(deliveryNoteLine);
    }

    @Override
    public void deleteDataObject(DeliveryNoteLine deliveryNoteLine) {

    }

    @Override
    public List<DeliveryNoteLine> getDataObjects() {
        return null;
    }

    @Override
    public DeliveryNoteLine getDataObject(int id) {
        return (DeliveryNoteLine)this.daoSupport.getDataObject(DeliveryNoteLine.class, id);
    }

    @Override
    public DeliveryNoteLine getDataObject(String s) {
        return null;
    }

    @Override
    public List<DeliveryNoteLine> getDataObjects(DeliveryNoteLineCO deliveryNoteLineCO) {
        return null;
    }

    @Override
    public List<DeliveryNoteLine> getDataObjects(Pages pages) {
        return null;
    }

    @Override
    public List<DeliveryNoteLine> getDataObjects(Pages pages, DeliveryNoteLineCO paramObj) {
        String sql = "select m.* from dn_delivery_note_line m where 1=1 and is_del = '0' ";

        Map<String, Object> args = new HashMap<String, Object>();
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "deliveryCode", "and m.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "status", "and m.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "isDel", "and m.", args);
        sql = sql + " order by m.id desc";

        this.daoSupport.validateDataObject(paramObj);

        Map<String, Class<?>> entity = new HashMap<String, Class<?>>();
        entity.put("m", DeliveryNoteLine.class);

        return this.daoSupport.getDataSqlByPage(sql, entity, args, pages);
    }

    @Override
    public List<Map<String, Object>> getDataObjectsArray(Pages pages, DeliveryNoteLineCO deliveryNoteLineCO) {
        return null;
    }

    @Override
    public List<DeliveryNoteLine> getDataObjectsForDataAuth(String s, Pages pages, DeliveryNoteLineCO deliveryNoteLineCO) {
        return null;
    }

    @Override
    public List<DeliveryNoteLine> getDataObjectsByDeliveryId(Integer id) {
        String sql = "select m.* from dn_delivery_note_line m where 1=1 and is_del = '0' ";
        sql = sql + " and delivery_id = : deliveryid";
        sql = sql + " order by m.id desc";

        Map<String, Object> args = new HashMap<String, Object>();
        args.put("deliveryid", id);

        Map<String, Class<?>> entity = new HashMap<String, Class<?>>();
        entity.put("m", DeliveryNoteLine.class);
        return this.daoSupport.selectDataSql(sql, entity, args);
    }
}
